package com.ktgj.service.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.ContractAttachment;
import com.ktgj.service.service.IContractAttachmentService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 合同附件Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@ControllerAdvice
@RestController
@RequestMapping("/contractattachment")
public class ContractAttachmentController extends BaseController
{
    @Autowired
    private IContractAttachmentService contractAttachmentService;

    /**
     * 查询合同附件列表
     */
    @PreAuthorize(hasPermi = "service:attachment:list")
    @GetMapping("/list")
    public TableDataInfo list(ContractAttachment contractAttachment)
    {
        startPage();
        List<ContractAttachment> list = contractAttachmentService.selectContractAttachmentList(contractAttachment);
        return getDataTable(list);
    }

    /**
     * 导出合同附件列表
     */
    @PreAuthorize(hasPermi = "service:attachment:export")
    @Log(title = "合同附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractAttachment contractAttachment) throws IOException
    {
        List<ContractAttachment> list = contractAttachmentService.selectContractAttachmentList(contractAttachment);
        ExcelUtil<ContractAttachment> util = new ExcelUtil<ContractAttachment>(ContractAttachment.class);
        util.exportExcel(response, list, "合同附件数据");
    }

    /**
     * 获取合同附件详细信息
     */
    @PreAuthorize(hasPermi = "service:attachment:query")
    @GetMapping(value = "/{attachmentId}")
    public AjaxResult getInfo(@PathVariable("attachmentId") Long attachmentId)
    {
        return AjaxResult.success(contractAttachmentService.selectContractAttachmentById(attachmentId));
    }

    /**
     * 新增合同附件
     */
    @PreAuthorize(hasPermi = "service:attachment:add")
    @Log(title = "合同附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractAttachment contractAttachment)
    {
        return toAjax(contractAttachmentService.insertContractAttachment(contractAttachment));
    }

    /**
     * 修改合同附件
     */
    @PreAuthorize(hasPermi = "service:attachment:edit")
    @Log(title = "合同附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractAttachment contractAttachment)
    {
        return toAjax(contractAttachmentService.updateContractAttachment(contractAttachment));
    }

    /**
     * 删除合同附件
     */
    @PreAuthorize(hasPermi = "service:attachment:remove")
    @Log(title = "合同附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attachmentIds}")
    public AjaxResult remove(@PathVariable Long[] attachmentIds)
    {
        return toAjax(contractAttachmentService.deleteContractAttachmentByIds(attachmentIds));
    }
}
